# flask web 网络编程文件
from flask import Flask, render_template, request
from vsearch import eating
from flask import escape
# noinspection PyUnresolvedReferences
from log_sys import log_request

# html 调用方法：render_template  按照 jinja2 规则
#

app = Flask(__name__)


# noinspection PyUnusedLocal
@app.route('/search4', methods=['POST'])
# 这些数据来自哪里？
def do_search() -> 'html':
    day = request.form['day']

    # title = '结果如下:'
    results = str(eating(day))
    return render_template('results.html',
                           # the_title=title,
                           the_day=day,
                           the_results=results)


@app.route('/')
@app.route('/entry')
def entry_page() -> 'html':
    # title = '欢迎来测试zhichao的元音字母是否存在小功能'
    return render_template('entry.html')
                           # the_title=title)
#用户日志系统
@app.route('/viewlog')
def view_the_log() -> 'html':
    """display the contents of thr log file as a html table"""
    contents = []
    with open('menu.log','r') as log:
        for line in log:
            contents.append([])
            for item in line.split('|'):
                contents[-1].append(escape(item))
    len(contents)
    titles = ('用户提交','远程地址','访问代理','用户结果')
    return render_template('viewlog.html',
                           the_title='日志系统后台',
                           the_row_title=titles,
                           the_data=contents)


if __name__ == '__main__':
    app.run(debug=True)
